﻿<%@ Page Language="C#" MasterPageFile="~/Theme/Stander/Stander.master" AutoEventWireup="true" CodeFile="Customer.aspx.cs" Inherits="Customer_Customer" Title="Untitled Page" %>
<%@ Register Src="../User Controls/ContactListControl.ascx" TagName="ContactListControl"
    TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
    <asp:View ID="MainView" runat="server">
    <h2>客户信息</h2>
    <asp:DetailsView ID="CustomerDetailsView" runat="server" 
    AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="CustomerDataSource"
    OnItemInserted="CustomerDetailsView_ItemInserted" OnItemInserting="CustomerDetailsView_ItemInserting" OnItemUpdating="CustomerDetailsView_ItemUpdating">
    <Fields>
        <asp:TemplateField HeaderText="名称：">
            <InsertItemTemplate>
                <asp:TextBox id="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                <asp:Label ID="lblNameError" runat="server" Text="" CssClass="error"></asp:Label>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" SetFocusOnError="true" 
                    runat="server" ErrorMessage="*" ControlToValidate="txtName">
                </asp:RequiredFieldValidator>
            </InsertItemTemplate>
            <EditItemTemplate>
                <asp:TextBox id="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
                <asp:Label ID="lblNameError" runat="server" Text="" CssClass="error"></asp:Label>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" SetFocusOnError="true" 
                    runat="server" ErrorMessage="*" ControlToValidate="txtName">
                </asp:RequiredFieldValidator>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:TextBox id="txtName" runat="server" Text='<%# Bind("Name") %>' ReadOnly="true"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Tel" HeaderText="电话：" SortExpression="Tel" />
        <asp:BoundField DataField="Fax" HeaderText="传真：" SortExpression="Fax" />
        <asp:TemplateField HeaderText="地址：">
            <InsertItemTemplate>
                <asp:TextBox id="txtAdress" runat="server" CssClass="long" 
                    TextMode="MultiLine" Rows="3" Text='<%# Bind("Address") %>'></asp:TextBox>
            </InsertItemTemplate>
            <EditItemTemplate>
                <asp:TextBox id="txtAdress" runat="server" CssClass="long" 
                    TextMode="MultiLine" Rows="3" Text='<%# Bind("Address") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:TextBox id="txtAdress" runat="server" CssClass="long" ReadOnly="true"
                    TextMode="MultiLine" Rows="3" Text='<%# Bind("Address") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="DealTimes" HeaderText="交易次数：" InsertVisible="false" ReadOnly="True" SortExpression="DealTimes" />
        <asp:TemplateField>
            <InsertItemTemplate>
                <asp:Button ID="Button1" CommandName="Insert" runat="server" Text="添加" />
            </InsertItemTemplate>
            <EditItemTemplate>
                <asp:Button ID="Button1" CommandName="Update" runat="server" Text="更新" />
            </EditItemTemplate>
            <ItemTemplate></ItemTemplate>
        </asp:TemplateField>
    </Fields>
</asp:DetailsView>
<csla:CslaDataSource ID="CustomerDataSource" runat="server" 
    TypeName="Active.Core.Customer, Active.Core" OnDeleteObject="CustomerDataSource_DeleteObject"
    OnInsertObject="CustomerDataSource_InsertObject" OnSelectObject="CustomerDataSource_SelectObject"
    OnUpdateObject="CustomerDataSource_UpdateObject" 
    TypeSupportsPaging="False" TypeSupportsSorting="False">
</csla:CslaDataSource>
<uc1:ContactListControl id="ContactListControl1" runat="server">
</uc1:ContactListControl>
<asp:PlaceHolder ID="ProductListPlaceHolder" runat="server">
<h2>客户的产品列表</h2>
    <asp:GridView ID="ProductsGridView" DataKeyNames="Id" runat="server" CssClass="normal mouseOver"
        DataSourceID="ProductsDataSource" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="名称" SortExpression="Name" />
            <asp:TemplateField HeaderText="版本(一行一个)" SortExpression="Versions">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" TextMode="MultiLine" Rows="8" runat="server" Text='<%# Bind("Versions") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Formater.VersionsToDisplay(Eval("Versions") as string) %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField SortExpression="Versions">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" CommandName="Update" runat="server">保存</asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" CommandName="Cancel" runat="server">取消</asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" CommandName="Edit" runat="server">编辑</asp:LinkButton>
                    <asp:LinkButton ID="LinkButton3" CommandName="Delete" 
                        OnClientClick="deleteConfirm(event);" 
                        runat="server">删除</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            暂无产品信息.
        </EmptyDataTemplate>
    </asp:GridView>
    <csla:CslaDataSource ID="ProductsDataSource" runat="server" 
        TypeName="Active.Core.Products, Active.Core" OnDeleteObject="ProductsDataSource_DeleteObject"
        OnSelectObject="ProductsDataSource_SelectObject"
        OnUpdateObject="ProductsDataSource_UpdateObject" 
        TypeSupportsPaging="False" TypeSupportsSorting="False">
    </csla:CslaDataSource>
    <p><asp:Button ID="btnAddProduct" runat="server" Text="添加产品" OnClick="btnAddProduct_Click" /></p>
</asp:PlaceHolder>    
    </asp:View>
    <asp:View ID="AddProductView" runat="server">
        <p><asp:Button ID="btnCancelSaveProduct" runat="server" Text="返回" OnClick="btnCancelSaveProduct_Click" /></p>
        <h2>填写产品信息</h2>
        <asp:DetailsView ID="ProductDetailsView" DataKeyNames="Id" runat="server" 
            DefaultMode="Insert" DataSourceID="ProductDataSource" AutoGenerateRows="False">
            <Fields>
                <asp:BoundField DataField="Name" HeaderText="名称" SortExpression="Name" />
                <asp:TemplateField HeaderText="版本<br />(一行一个)" SortExpression="Versions">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" TextMode="MultiLine" Rows="8" runat="server" Text='<%# Bind("Versions") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" TextMode="MultiLine" Rows="8" runat="server" Text='<%# Bind("Versions") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Versions") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="true" ShowInsertButton="true" 
                    ShowCancelButton="false" InsertText="添加" EditText="更新" ButtonType="Button" />
            </Fields>
        </asp:DetailsView>
        <csla:CslaDataSource ID="ProductDataSource" runat="server" 
            TypeName="Active.Core.Product, Active.Core"
            OnInsertObject="ProductDataSource_InsertObject"
            TypeSupportsPaging="False" TypeSupportsSorting="False">
        </csla:CslaDataSource>
    </asp:View>
</asp:MultiView>
</asp:Content>

